const { sequelize } = require("../../core/db");
const { Sequelize, Model, QueryTypes } = require("sequelize");
const { Activity } = require("@models/activity");

class Enroll extends Model {}

Enroll.init(
  {
    enroll_id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    admin_id: {
      type: Sequelize.INTEGER,
      allowNull: false,
      comment: "创建活动的管理员id",
    },
    uid: {
      type: Sequelize.INTEGER,
      allowNull: false,
      comment: "报名的用户id",
    },
    activity_id: {
      type: Sequelize.INTEGER,
      allowNull: false,
      comment: "活动id",
    },
    price: {
      type: Sequelize.INTEGER,
      allowNull: false,
      comment: "报名费用",
    },
    //活动详情
    activity_details: {
      type: Sequelize.TEXT,
      allowNull: false,
      comment: "活动详情",
    },
    // 报名订单号
    enroll_number: {
      type: Sequelize.STRING,
      allowNull: false,
      defaultValue: () => {
        return "OTN" + Date.now() + "" + Math.floor(Math.random() * 10000);
      },
      comment: "报名订单号",
    },
    // 报名订单是否完成
    enroll_finish: {
      type: Sequelize.INTEGER,
      allowNull: false,
      comment: "报名订单是否完成",
      defaultValue: 0, // 0:未完成 1:已核销
    },
    // 报名订单状态
    enroll_status: {
      type: Sequelize.INTEGER,
      allowNull: false,
      comment: "报名订单状态",
      defaultValue: 0, // -1:已退款 0: 待支付 1: 已支付 2: 已关闭 3: 退款中
    },
  },

  {
    sequelize,
    tableName: "enroll",
    hooks: {
      afterCreate: async (enroll, option) => {},
      afterDestroy: (enroll, option) => {},
    },
  }
);

module.exports = {
  Enroll,
};
